<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ViewAction
 *
 * @author wuxiaofeng
 */
class ViewAction extends MenuAction{
   
         public function articles(){
             if(isset($_GET['articleid']) && intval($_GET['articleid'])){
                 $content_id=$_GET['articleid'];
                 $Content=M("Content");
                 $ContentThumb=M("ContentThumb");
                 $Category=M("Category");
                 
                 //read current article of the content_id
                 $articlecont=$Content->query("SELECT * FROM `c_content`  LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content WHERE content_id IN(
SELECT content_id FROM `c_content` where content_id=$content_id)");
                 
                 
                  
           /* $contentpic1=$Content->query("SELECT * FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content WHERE content_id IN(
SELECT MAX(content_id) FROM `c_content` GROUP BY channel_id) AND content_state=1 AND content_isthumb=1 ORDER BY content_id DESC" );
            $contentpic2=$Content->query("SELECT * FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content WHERE content_id NOT IN(
SELECT MAX(content_id) FROM `c_content` GROUP BY channel_id) AND content_state=1 AND content_isthumb=1 ORDER BY content_id DESC LIMIT 2");
            
            $contentpic3=$Content->query("SELECT * FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content 
                                          WHERE content_id IN(SELECT MIN(content_id) FROM `c_content` WHERE content_id IN(SELECT MAX(content_id) FROM `c_content` GROUP BY channel_id)  AND content_id>$content_id  )AND content_state=1 AND content_isthumb=1");
            $contentpic4=$Content->query("SELECT * FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content 
                                          WHERE content_id IN(SELECT MAX(content_id) FROM `c_content` WHERE content_id IN(SELECT MAX(content_id) FROM `c_content` GROUP BY channel_id)  AND content_id<$content_id  )AND content_state=1 AND content_isthumb=1");
            var_dump($contentpic4);
            exit;
            
            var_dump($contentpic3);
            exit;*/
                 $nextarticle=$Content->query("SELECT *FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content 
                                               WHERE content_id IN(SELECT MAX(content_id) FROM `c_content` WHERE  content_id<$content_id  AND content_state=1 AND content_isthumb=1)");
                 $prevarticle=$Content->query("SELECT *FROM `c_content` LEFT JOIN `c_content_thumb` on `c_content`.content_id=`c_content_thumb`.thumb_content 
                                               WHERE content_id IN(SELECT MIN(content_id) FROM `c_content` WHERE  content_id>$content_id  AND content_state=1 AND content_isthumb=1)");
                 
		 /*$data['content_id'] = $articlecont['content_id'];
		 $data['content_click_count'] = $continfo['content_click_count']+1;
		 $Content->data($data)->save();*/
                 if(! empty($articlecont)){
                    $this->assign('articlecont1',$articlecont[0]);
                    if(!empty($prevarticle)){
                        $this->assign('prevarticle',$prevarticle[0]);
                    }
                    if(!empty($nextarticle)){
                        $this->assign('nextarticle',$nextarticle[0]);
                    }
                     $this->display();
                 }else{
                     $this->redirect('Index/index', '',0,'');
                 }
             }else{
			$this->redirect('Index/index', '',0,'');
		}
         }
}

?>
